/**
 * @name: loginStore
 * @Description:
 * @Author: 方琦
 * @Date: 2022/8/17 15:09
 **/
import { makeAutoObservable } from "mobx";
import service from "../service";

class UserStore {
    constructor() {
        makeAutoObservable(this);
    }

    userInfo = sessionStorage.getItem("userInfo") ? JSON.parse(sessionStorage.getItem("userInfo")) : [];

    get token() {
        if (sessionStorage.getItem('token')) return sessionStorage.getItem('token');
        else return '';
    }

    set token(data) {
        sessionStorage.setItem('token', data);
    }

    userLogin(userInput) {
        //只进行数据处理，不进行界面的提示信息
        return new Promise((resolve, reject) => {
            //    发起axios请求
            service.userService.User_Login(userInput).then(data => {

                this.userInfo = data
                sessionStorage.setItem('userInfo', JSON.stringify(data));

                resolve(data)
            }).catch(err => {
                reject(err)
            })
        })
    }
}

export default UserStore
